
<template>
  <div>
    <el-container>

      <el-header height="60px">
        <div>
          <span>轻量级培养方案管理系统</span>
        </div>
        <div>
          <el-button type="danger" @click="logout" round icon="el-icon-refresh-right" plain>退出登录</el-button>
        </div>






      </el-header>
      <el-container>
        <el-header width="100px">
          <el-menu
            class="el-menu--horizontal"
            @open="handleOpen"
            @close="handleClose"
            background-color="white"
            text-color="black"
            active-text-color="black"
            unique-opened
            router
            :collapse-transition="true">
            <el-menu-item index="/FundamentalInfo"><i class="el-icon-lightning"></i>课程基本信息</el-menu-item>
            <el-menu-item index="/Course_home"><i class="el-icon-school"></i>课程详细内容信息</el-menu-item>
            <el-menu-item index="/Curriculum_relation"><i class="el-icon-files"></i>课程先修后修</el-menu-item>
            <el-menu-item index="/References"><i class="el-icon-lightning"></i>课程参考书目</el-menu-item>
          </el-menu>
        </el-header>

      </el-container>
    </el-container>
    <el-card>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>课程负责人</el-breadcrumb-item>
        <el-breadcrumb-item>课程信息管理</el-breadcrumb-item>
        <el-breadcrumb-item>课程详细信息</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="searchForm">

        <el-form :inline="true" class="demo-form-inline">
          <el-form-item>
            <el-input v-model="queryInfo.query" placeholder="" clearable @clear="getCourseList"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="" @click="getCourseList" icon="el-icon-search">查询</el-button>
          </el-form-item>
          <el-button style="position: absolute; right: 720px" type="" @click="addDialogVisible=true">添加信息</el-button>
        </el-form>

        <el-dialog title="添加基本信息" :visible.sync="addDialogVisible" width="40%" @close="addDialogClose">
          <el-form :model="addForm" :rules="addFormRules" ref="addFormRef" label-width="150px">

            <el-form-item label="课程编号" prop="courseid">{{this.$session.get('bulls')}}
              <el-input v-model="addForm.courseid" v-show="false" readonly="readonly"></el-input>
            </el-form-item>


            <el-form-item label="周课时" prop="weeklytime" >
              <el-input v-model="addForm.weeklytime" ></el-input>
            </el-form-item>

            <el-form-item label="总目标" prop="totalgoal" >
              <el-input v-model="addForm.totalgoal" ></el-input>
            </el-form-item>

            <el-form-item label="课程描述" prop="coursedes">
              <el-input v-model="addForm.coursedes"></el-input>
            </el-form-item>
            <el-form-item label="教学方法" prop="ways">
              <el-input v-model="addForm.ways"></el-input>
            </el-form-item>
            <el-form-item label="考核方式" prop="tests">
              <el-input v-model="addForm.tests"></el-input>
            </el-form-item>

          </el-form>

          <div slot="footer" class="dialog-footer">
            <el-button @click="addDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="addCourserelation">确 认</el-button>
          </div>
        </el-dialog>






        <el-table :header-cell-style="{background:'#808080',color:'#FFFFFF'}" border stripe :data="List" style="width: 100%">

          <el-table-column prop="courseid" label="课程编号" width="160" align="center">
          </el-table-column>
          <el-table-column prop="weeklytime" label="周课时" width="160" align="center">
          </el-table-column>
          <el-table-column prop="totalgoal" label="总目标" width="360" align="center">
          </el-table-column>
          <el-table-column prop="coursedes" label="课程描述" width="360" align="center">
          </el-table-column>

          <el-table-column prop="ways" label="教学方式" width="160" align="center">
          </el-table-column>
          <el-table-column prop="tests" label="教学方法" width="160" align="center">
          </el-table-column>

          <el-table-column label="修改  /  删除" align="center">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="dark" content="编辑信息" placement="top-start">
                <el-button  icon="el-icon-edit" circle @click="editParagraph(scope.row.courseid)"></el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="删除信息" placement="top-start">
                <el-button type="" icon="el-icon-delete" circle @click="deleteParagraph(scope.row.courseid)"></el-button>
              </el-tooltip>
            </template>
          </el-table-column>


        </el-table>


        <el-dialog title="修改基础信息" :visible.sync="editDialogVisible" width="50%" @close="editDialogClose" append-to-body = "true">
          <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="160px">


            <el-form-item label="周课时" prop="weeklytime" >
              <el-input v-model="editForm.weeklytime" ></el-input>
            </el-form-item>

            <el-form-item label="总目标" prop="totalgoal" >
              <el-input v-model="editForm.totalgoal" ></el-input>
            </el-form-item>

            <el-form-item label="课程描述" prop="coursedes">
              <el-input v-model="editForm.coursedes"></el-input>
            </el-form-item>
            <el-form-item label="教学方法" prop="ways">
              <el-input v-model="editForm.ways"></el-input>
            </el-form-item>
            <el-form-item label="考核方式" prop="tests">
              <el-input v-model="editForm.tests"></el-input>
            </el-form-item>

          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="editDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="editParagraphInfo">修 改</el-button>
          </div>
        </el-dialog>

      </div>

      <div>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pageNum"
          :page-sizes="[4]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>


<script>
  export default {

    create(){
      this.getCourseList();
    },
    data() {
      return {
        queryInfo:{
          query:'',//查询信息
          role:this.$session.get('bulls'),
          pageNum:1,
          pageSize:4
        },
        List:[],
        total:0,
        addDialogVisible:false,
        editDialogVisible:false,
        infoDialogVisible:false,
        Form:{
          courseid:this.$session.get('bulls'),
          weeklytime:'',
          totalgoal:'',
          coursedes:'',
          ways:'',
          tests:'',

        },
        addForm:{
          courseid:this.$session.get('bulls'),
          weeklytime:'',
          totalgoal:'',
          coursedes:'',
          ways:'',
          tests:'',
        },
        editForm:{
          courseid:this.$session.get('bulls'),
          weeklytime:'',
          totalgoal:'',
          coursedes:'',
          ways:'',
          tests:'',
        },
        editFormRules: {

          weeklytime: [
            { required: true, message: '请输入周课时', trigger: 'blur' },

          ],

          totalgoal: [
            { required: true, message: '请输入目标', trigger: 'blur' },

          ],
          coursedes: [
            { required: true, message: '请输入课程描述', trigger: 'blur' },

          ],
          ways: [
            { required: true, message: '请输入教学方式', trigger: 'blur' },

          ],
          tests: [
            { required: true, message: '请输入考核方式', trigger: 'blur' },

          ],

        },
        addFormRules: {

          weeklytime: [
            { required: true, message: '请输入周课时', trigger: 'blur' },

          ],

          totalgoal: [
            { required: true, message: '请输入目标', trigger: 'blur' },

          ],
          coursedes: [
            { required: true, message: '请输入课程描述', trigger: 'blur' },

          ],
          ways: [
            { required: true, message: '请输入教学方式', trigger: 'blur' },

          ],
          tests: [
            { required: true, message: '请输入考核方式', trigger: 'blur' },

          ],

        },
        FormRules: {

        },



      }
    },


    methods: {
      async getCourseList () {
        const { data: res } = await this.$http.get("CourseSimples/AllCourseSimple" ,{ params: this.queryInfo });
        this.List = res.data;
        this.total = res.numbers;
      },
      editParagraphInfo () {
        this.$refs.editFormRef.validate(async valid => {
          console.log(valid);
          if (!valid) return;

          const { data: res } = await this.$http.put("CourseSimples/CourseSimple", this.editForm);
          console.log(res);
          if (res !== "success") return this.$message.error("修改失败");
          this.$message.success("修改成功");

          this.editDialogVisible = false;
          this.getCourseList();
        });
      },
      async editParagraph(courseid){
        const {data:res} = await this.$http.get("CourseSimples/CourseSimpleMessage?courseid="+courseid);
        this.editForm = res;
        this.editDialogVisible = true;
      },
      handleSizeChange (newSize) {
        this.queryInfo.pageSize = newSize;
        this.getCourseList();
      },
      handleCurrentChange (newPage) {
        this.queryInfo.pageNum = newPage;
        this.getCourseList();
      },
      addDialogClose () {
        this.$refs.addFormRef.resetFields();
      },
      editDialogClose () {
        this.$refs.editFormRef.resetFields();
      },
      logout(){
        window.sessionStorage.clear();
        this.$router.push({ path: "/login"});
      },
      async deleteParagraph (courseid) {

        const confirmResult = await this.$confirm('是否删除该关联？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).catch(err => err)
        if (confirmResult !== 'confirm') {
          return ;
        }
        const { data: res } = await this.$http.delete("CourseSimples/CourseSimple?courseid="+ courseid);
        if (res !== "success") {
          return this.$message.error("删除失败");
        }
        this.$message.success("删除成功");
        this.getCourseList();
      },

      addCourserelation () {
        this.$refs.addFormRef.validate(async valid => {
          if (!valid) return;
          const { data: res } = await this.$http.post("CourseSimples/CourseSimple", this.addForm);
          if (res !== "success") {
            return this.$message.error("添加失败!")
          }
          this.$message.success("添加成功！")
          this.addDialogVisible = false;
          this.getCourseList();
        })
      },
    }
  }
</script>




<style scoped>
  .el-header{
    background: lightslategray;
    color: white;
    font-size: 25px;
    align-items: center;
    justify-content: space-between;
    display: flex;
  }
  .el-main{
    background-color: whitesmoke;
  }

</style>
